18: ' the copy routine based on moving 256 bytes at a time
19: lngFileSize = FileLen(txtSourceFile.Text)
20: intBufferCount = lngFileSize / 256
21:
22: ' Open the source and destination files
23: Open txtSourceFile.Text For Binary As #1
24: Open txtTargetFile.Text For Binary As #2
25:
26: ' This routine loops until the entire file is copied
27: For intLoopCtr = 1 To intBufferCount + 1
28: Get #1, , strInByte
29: Put #2, , strInByte
30: Next intLoopCtr
31:
32: ' After the copy is complete close both files
33: Close #1 ' Close file.
34: Close #2 ' Close file.
35: ' Inform the user that the function is complete
36: MsgBox Copy function complete, vbInformation
37: End Sub.
For a file copy process, the errors that might occur are as follows
File not found
File already open
Device I/O error
Disk full
Device unavailable
Permission denied
Disk not ready
Path/File access error
Path not found
To handle these errors, you would create a routine that resembles the one in Listing 16.2.
LISTING 16.2. ERROREX1.TXTA SAMPLE ERROR ROUTINE FOR A FILE COPY PROCESS.
1: FileCopyError:
2: On Error GoTo 0
3: Select Case Err.Number
4: Case 53 'File not found